home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / doc / SplitList.3 < prev    next >
Text File  |  1993-02-14  |  6KB  |  158 lines

  1. '\"
  2. '\" Copyright 1989-1991 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. .so man.macros
  11. .HS Tcl_SplitList tcl
  12. .BS
  13. .SH NAME
  14. Tcl_SplitList, Tcl_Merge, Tcl_ScanElement, Tcl_ConvertElement \- manipulate Tcl lists
  15. .SH SYNOPSIS
  16. .nf
  17. \fB#include <tcl.h>\fR
  18. .sp
  19. int
  20. \fBTcl_SplitList\fR(\fIinterp, list, argcPtr, argvPtr\fR)
  21. .sp
  22. char *
  23. \fBTcl_Merge\fR(\fIargc, argv\fR)
  24. .sp
  25. .VS
  26. int
  27. \fBTcl_ScanElement\fR(\fIsrc, flagsPtr\fR)
  28. .sp
  29. int
  30. \fBTcl_ConvertElement\fR(\fIsrc, dst, flags\fR)
  31. .VE
  32. .SH ARGUMENTS
  33. .AS Tcl_Interp ***argvPtr
  34. .AP Tcl_Interp *interp out
  35. Interpreter to use for error reporting.
  36. .AP char *list in
  37. Pointer to a string with proper list structure.
  38. .AP int *argcPtr out
  39. Filled in with number of elements in \fIlist\fR.
  40. .AP char ***argvPtr out
  41. \fI*argvPtr\fR will be filled in with the address of an array of
  42. pointers to the strings that are the extracted elements of \fIlist\fR.
  43. There will be \fI*argcPtr\fR valid entries in the array, followed by
  44. a NULL entry.
  45. .AP int argc in
  46. Number of elements in \fIargv\fR.
  47. .AP char **argv in
  48. Array of strings to merge together into a single list.
  49. Each string will become a separate element of the list.
  50. .AP char *src in
  51. .VS
  52. String that is to become an element of a list.
  53. .AP int *flagsPtr in
  54. Pointer to word to fill in with information about \fIsrc\fR.
  55. The value of *\fIflagsPtr\fR must be passed to \fBTcl_ConvertElement\fR.
  56. .AP char *dst in
  57. Place to copy converted list element.  Must contain enough characters
  58. to hold converted string.
  59. .AP int flags in
  60. Information about \fIsrc\fR. Must be value returned by previous
  61. call to \fBTcl_ScanElement\fR, possibly OR-ed
  62. with \fBTCL_DONT_USE_BRACES\fR.
  63. .VE
  64. .BE
  65.  
  66. .SH DESCRIPTION
  67. .PP
  68. These procedures may be used to disassemble and reassemble Tcl lists.
  69. \fBTcl_SplitList\fR breaks a list up into its constituent elements,
  70. returning an array of pointers to the elements using
  71. \fIargcPtr\fR and \fIargvPtr\fR.
  72. While extracting the arguments, \fBTcl_SplitList\fR obeys the usual
  73. rules for backslash substitutions and braces.  The area of
  74. memory pointed to by \fI*argvPtr\fR is dynamically allocated;  in
  75. addition to the array of pointers, it
  76. also holds copies of all the list elements.  It is the caller's
  77. responsibility to free up all of this storage by calling
  78. .DS
  79. \fBfree\fR((char *) \fI*argvPtr\fR)
  80. .DE
  81. when the list elements are no longer needed.
  82. .PP
  83. \fBTcl_SplitList\fR normally returns \fBTCL_OK\fR, which means the list was
  84. successfully parsed.
  85. If there was a syntax error in \fIlist\fR, then \fBTCL_ERROR\fR is returned
  86. and \fIinterp->result\fR will point to an error message describing the
  87. problem.
  88. If \fBTCL_ERROR\fR is returned then no memory is allocated and \fI*argvPtr\fR
  89. is not modified.
  90. .PP
  91. \fBTcl_Merge\fR is the inverse of \fBTcl_SplitList\fR:  it
  92. takes a collection of strings given by \fIargc\fR
  93. and \fIargv\fR and generates a result string
  94. that has proper list structure.
  95. This means that commands like \fBindex\fR may be used to
  96. extract the original elements again.
  97. In addition, if the result of \fBTcl_Merge\fR is passed to \fBTcl_Eval\fR,
  98. it will be parsed into \fIargc\fR words whose values will
  99. be the same as the \fIargv\fR strings passed to \fBTcl_Merge\fR.
  100. \fBTcl_Merge\fR will modify the list elements with braces and/or
  101. backslashes in order to produce proper Tcl list structure.
  102. The result string is dynamically allocated
  103. using \fBmalloc()\fR;  the caller must eventually release the space
  104. using \fBfree()\fR.
  105. .PP
  106. If the result of \fBTcl_Merge\fR is passed to \fBTcl_SplitList\fR,
  107. the elements returned by \fBTcl_SplitList\fR will be identical to
  108. those passed into \fBTcl_Merge\fR.
  109. However, the converse is not true:  if \fBTcl_SplitList\fR
  110. is passed a given string, and the resulting \fIargc\fR and
  111. \fIargv\fR are passed to \fBTcl_Merge\fR, the resulting string
  112. may not be the same as the original string passed to \fBTcl_SplitList\fR.
  113. This is because \fBTcl_Merge\fR may use backslashes and braces
  114. differently than the original string.
  115. .PP
  116. .VS
  117. \fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR are the
  118. procedures that do all of the real work of \fBTcl_Merge\fR.
  119. \fBTcl_ScanElement\fR scans its \fIsrc\fR argument
  120. and determines how to use backslashes and braces
  121. when converting it to a list element.
  122. It returns an overestimate of the number of characters
  123. required to represent \fIsrc\fR as a list element, and
  124. it stores information in \fI*flagsPtr\fR that is needed
  125. by \fBTcl_ConvertElement\fR.
  126. .PP
  127. \fBTcl_ConvertElement\fR is a companion procedure to \fBTcl_ScanElement\fR.
  128. It does the actual work of converting a string to a list element.
  129. Its \fIflags\fR argument must be the same as the value returned
  130. by \fBTcl_ScanElement\fR.
  131. \fBTcl_ConvertElement\fR writes a proper list element to memory
  132. starting at *\fIdst\fR and returns a count of the total number
  133. of characters written, which will be no more than the result
  134. returned by \fBTcl_ScanElement\fR.
  135. \fBTcl_ConvertElement\fR writes out only the actual list element
  136. without any leading or trailing spaces: it is up to the caller to
  137. include spaces between adjacent list elements.
  138. .PP
  139. \fBTcl_ConvertElement\fR uses one of two different approaches to
  140. handle the special characters in \fIsrc\fR.  Wherever possible, it
  141. handles special characters by surrounding the string with braces.
  142. This produces clean-looking output, but can't be used in some situations,
  143. such as when \fIsrc\fR contains unmatched braces.
  144. In these situations, \fBTcl_ConvertElement\fR handles special
  145. characters by generating backslash sequences for them.
  146. The caller may insist on the second approach by OR-ing the
  147. flag value returned by \fBTcl_ScanElement\fR with
  148. \fBTCL_DONT_USE_BRACES\fR.
  149. Although this will produce an uglier result, it is useful in some
  150. special situations, such as when \fBTcl_ConvertElement\fR is being
  151. used to generate a portion of an argument for a Tcl command.
  152. In this case, surrounding \fIsrc\fR with curly braces would cause
  153. the command not to be parsed correctly.
  154. .VE
  155.  
  156. .SH KEYWORDS
  157. backslash, convert, element, list, merge, split, strings
  158.